package com.life.goal.adapter.web.controller;

import com.alibaba.fastjson.JSON;
import com.life.goal.adapter.common.JsonResult;
import com.life.goal.application.dto.request.InsertOralBatchRequest;
import com.life.goal.application.dto.request.InsertOralRequest;
import com.life.goal.application.dto.request.InsertWordRequest;
import com.life.goal.application.service.EnglishDataService;
import com.life.goal.domain.entity.OralSentence;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 英语相关功能的控制层
 */
@RestController
@ResponseBody
@Slf4j
@RequestMapping("/english")
public class EnglishController {

    @Autowired
    private EnglishDataService englishDataService;

    /**
     * 新增英语口语
     */
    @PostMapping("/insert/oral")
    public JsonResult<Boolean> insertOral(@RequestBody InsertOralRequest request) {
        log.info(JSON.toJSONString(request));
        englishDataService.saveOral(request);
        return JsonResult.buildSuccess();
    }

    /**
     * 批量新增英语口语
     */
    @PostMapping("/insert/batch/oral")
    public JsonResult<Boolean> insertOralBatch(@RequestBody InsertOralBatchRequest request) {
        log.info(JSON.toJSONString(request));
        englishDataService.saveOralBatch(request);
        return JsonResult.buildSuccess();
    }


    /**
     * 新增英语单词
     */
    @PostMapping("/insert/word")
    public JsonResult<Boolean> insertWord(@RequestBody InsertWordRequest request) {
        log.info(JSON.toJSONString(request));
        englishDataService.saveWord(request);
        return JsonResult.buildSuccess();
    }

    /**
     * 新增英语单词
     */
    @PostMapping("/insert/batch/word")
    public JsonResult<Boolean> insertWordBatch(@RequestBody List<InsertWordRequest> list) {
        log.info(JSON.toJSONString(list));
        englishDataService.saveWordBatch(list);
        return JsonResult.buildSuccess();
    }

    /**
     * 查询全部oral语句
     */
    @PostMapping("/query/oral")
    public JsonResult<List<OralSentence>> queryOralSentencesAll() {
        return JsonResult.buildSuccess(englishDataService.queryAllOralSentences());
    }
}
